/**
 * Created by hezhijie on 2016/11/22.
 */
var machineStatisticDetailModule = angular.module("machineStatisticDetail", []);
machineStatisticDetailModule.controller("machineStatisticDetailCtrl", ['$scope',
    function ($scope) {
        $scope.init = function () {
            $scope.queryParams = {}
            $scope.queryDetectLogDetail();
        }

        $scope.queryDetectLogDetail = function () {
            $post(basePath + "/rest/detect/_queryMachineDetectStatisticWithFileInfo", {id: $scope.$stateParams.id}, function (result) {
                if (result.resultValue != null) {
                    $scope.detectLog = result.resultValue[0];
                    var scanFileInfo = $.parseJSON($scope.detectLog.scanFileInfo);
                    var reportFileInfoMap = {};
                    var reportFileInfoArray = $.parseJSON($scope.detectLog.reportFileInfo);
                    if (reportFileInfoArray == null) {
                        $.each(scanFileInfo, function (index, fileInfo) {
                            fileInfo["statusTxt"] = "未处理";
                            fileInfo["status"] = 1;
                            fileInfo["class"] = "bg-danger";
                        })
                    } else {
                        $.each(reportFileInfoArray, function (index, v) {
                            reportFileInfoMap[v["Content"] + v["Size"]] = v;
                        })
                        $.each(scanFileInfo, function (index, fileInfo) {
                            var reportFileInfo = reportFileInfoMap[fileInfo["Content"] + fileInfo["Size"]];
                            if (reportFileInfo) {
                                fileInfo["statusTxt"] = "未处理";
                                fileInfo["status"] = 1;
                                fileInfo["class"] = "bg-danger";
                                delete reportFileInfoMap[fileInfo["Content"] + fileInfo["Size"]];
                            } else {
                                fileInfo["statusTxt"] = "已处理";
                                fileInfo["status"] = 2;
                            }
                        });
                        scanFileInfo.sort(function(a,b){
                            if(a["status"]==b["status"]){
                                return a["Content"].localeCompare(b["Content"]);
                            }
                            return a["status"]-b["status"];
                        })
                    }
                    $scope.detectLog.scanFileInfo=scanFileInfo;
                    $scope.page={
                        pageNum:1,
                        pageSize:500,
                        totalSize:scanFileInfo.length
                    }
                    $scope.moreScanFile();
                    $scope.$apply();
                }
            })
        }

        $scope.moreScanFile=function(){
            $scope.showScanFileInfo=$scope.detectLog.scanFileInfo.slice( ($scope.page.pageNum-1)*$scope.page.pageSize,$scope.page.pageNum*$scope.page.pageSize);
        }

        $scope.init();
    }
]);
